/**
 * 音效，音乐管理工具
 */

import gamePrefabMgr, { soundName } from "./gamePrefabMgr"
import gameStorage from "./gameStorage"



export default class AudioManager {

    static setSoundEvent(){
        cc.director.on('main_bg', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.stopMusic()
            cc.audioEngine.playMusic(gamePrefabMgr.Instance.soundRes[soundName.main_bg], true)
        }, this)
        cc.director.on('game_bg0', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.stopMusic()
            cc.audioEngine.playMusic(gamePrefabMgr.Instance.soundRes[soundName.main_bg], true)
        }, this)
        cc.director.on('game_bg1', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.stopMusic()
            cc.audioEngine.playMusic(gamePrefabMgr.Instance.soundRes[soundName.main_bg], true)
        }, this)
        cc.director.on('game_bg2', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.stopMusic()
            cc.audioEngine.playMusic(gamePrefabMgr.Instance.soundRes[soundName.main_bg], true)
        }, this)
        cc.director.on('game_bg3', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.stopMusic()
            cc.audioEngine.playMusic(gamePrefabMgr.Instance.soundRes[soundName.main_bg], true)
        }, this)
        cc.director.on('answerright', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.answerright], false)
        }, this)
        cc.director.on('error', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.error], false)
        }, this)
        cc.director.on('fail', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.fail], false)
        }, this)
        cc.director.on('win', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.win], false)
        }, this)
        cc.director.on('hit', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.hit], false)
        }, this)
        cc.director.on('click', ()=>{
            if(gameStorage.getMusic() == 1) return
            cc.audioEngine.playEffect(gamePrefabMgr.Instance.soundRes[soundName.click], false)
        }, this)
    }
}
